<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
    <style>
        .box {
            height: 400px;
            width: 400px;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <div class="app">
        <input type="text" v-jujiao>
        <input type="text" v-jiao>
        <!-- wsc中不能有大写字母 -->
        <h1 v-change-color="color">{{msg}}</h1>
        <div class="box" v-change-mouse="color">

        </div>
    </div>
    <script>
        //自定聚焦指令
        Vue.directive('jujiao', {
            inserted: function(el) {
                el.focus()
            }
        })

        //自定义改变文字颜色的指令
        Vue.directive('changeColor', {
            inserted: function(el, binding) {
                // console.log(binding);
                el.style.color = binding.value
                var s = JSON.stringify
                el.innerHTML =
                    'name 指令名: ' + s(binding.name) + '<br>' +
                    'value 指令值: ' + s(binding.value) + '<br>' +
                    'expression 表达式: ' + s(binding.expression) + '<br>' +
                    'argument: 参数' + s(binding.arg) + '<br>' +
                    'modifiers 修饰符: ' + s(binding.modifiers) + '<br>';
            }
        })

        //定义指令改变鼠标
        Vue.directive('changeMouse', {
            inserted: function(el, binding) {
                console.log(binding);
                console.log(binding.arg);
            }
        })

        const vm = new Vue({
            data: {
                msg: "nishishahua,nihaishuijiao",
                color: "red",
            },
            directives: {
                jiao: {
                    // 指令的定义
                    inserted: function(el) {
                        el.focus()
                    }
                }
            }
        }).$mount(".app")
    </script>
</body>

</html>